/*
 * Project : Linuxbox
 * File    : UserManEdit.java
 * Version : 1.0
 * Author  : Kevin Zhang
 *
 * Copyright (c) 2000-2001 by Linuxbox, Inc.
 * All rights reserved.
 */
package linuxbox.admin.servlet;

import javax.servlet.http.*;

import linuxbox.common.*;
import linuxbox.admin.logic.*;
import linuxbox.exception.*;

/**
 * This class is used when the user password is to be changed.
 *
 * @author Kevin Zhang 
 * @version 1.0
 */
public class ChangePasswdAction extends Action {
    protected static String successJSP = null;
    
    public void doAction(HttpSession aSession, BoxSession aBoxSession, 
    HttpServletRequest req, HttpServletResponse res) throws Exception {
        String newPassword = req.getParameter("NEW_PASSWORD");
        String confirmPassword = req.getParameter("CONFIRM_PASSWORD");

        if (newPassword != null && confirmPassword != null 
        && newPassword.equals(confirmPassword)) {
            UserManager um = UserManager.getInstance();
            HttpSession session = req.getSession(false);
            BoxSession sec = (BoxSession)session.getAttribute("BoxSession");
            int id = sec.getID();
            
            um.changePassword(id, newPassword); 
            redirectFile(successJSP, req, res);
        } else {
            throw new LinuxboxException(ExceptionHelper.ADMIN, "A000002");
        }
    }

    public void setSuccessJSP(String str) {
        //"/linuxbox/jsp/admin/PasswdSuccess.jsp"
        successJSP = str;
    }
}